<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
</html>
<script>
  function ajaxGetPromise(obj) {
    let { url, params } = obj;
    return new Promise(function (resolve, reject) {
      let searchParams = new URLSearchParams(params);
      let xhr = new XMLHttpRequest();
      xhr.open("GET", `${url}?${searchParams.toString()}`);
      xhr.setRequestHeader("content-type", "application/json");
      xhr.send();
      xhr.onload = function () {
        if (xhr.status == 200) {
          let obj = JSON.parse(xhr.responseText);
          resolve(obj);
        }
      };
    });
  }
  let url = "http://localhost:3000/todos";
  ajaxGetPromise({ url, params: { _page: 1 } }).then((r) => {
    r;
    console.log(r);
  });
</script>
